﻿using System;
using System.Collections.ObjectModel;
using Moq;
using Prompts.Prompting.Model;
using Prompts.Prompting.ViewModels;
using Prompts.Prompting.ViewModels.Search;

namespace Test.Prompts.Infrastructure.Fakes
{
    internal class FakeAsynchronousSearchService
    {
        private readonly Mock<IAsynchronousSearchService> _mock;
        private Action<ObservableCollection<ISearchablePromptItem>> _callback;

        public FakeAsynchronousSearchService()
        {
            _mock = new Mock<IAsynchronousSearchService>();
        }

        public IAsynchronousSearchService Object
        {
            get { return _mock.Object; }
        }

        public void SetupSearch(string searchExpression)
        {
            var setup = _mock.Setup(
                s =>
                s.Search(
                    searchExpression,
                    It.IsAny<Action<ObservableCollection<ISearchablePromptItem>>>()));

            setup.Callback((string s, Action<ObservableCollection<ISearchablePromptItem>> c) =>
            {
                _callback = c;
            });
        }

        public void ExecuteSearchCallback(ObservableCollection<ISearchablePromptItem> promptItemCollection)
        {
            _callback(promptItemCollection);
        }
    }
}
